<?php
class Pages_Model_Tree extends Zen_Tree {
	
	public $multilang = true;
	
	public function __construct() {
		$table = new Zend_Db_Table('pages_tree');
		$this->table = $table;
		$types = array(
						'root' => array (
									'icon' => '/cms/res/icons/drive.png', 
									'label' => 'Страницы сайта', 
									'valid_children' => array ('page' ), 
									'start_drag' => false, 
									'move_node' => false, 
									'delete_node' => false, 
									'remove' => false ), 
						'item' => array (
									'table' => 'pages_item', 
									'form' => 'Pages_Form_Item', 
									'label' => 'страницу', 
									'view' => 'form.phtml', 
									'icon' => '/cms/res/icons/page.png', 
									'attributes' => array ('active' ), 
									'valid_children' => array ('page' ), 
									'start_drag' => true, 
									'move_node' => true, 
									'delete_node' => true, 
									'remove' => true ) 
					);
					
		$this->setTypes($types);
		
		$this->grid=array(
					'types'=>array('item'),
					'columns'=>array(
										array('width'=>'300','header'=>' '),
										array('cellClass'=>'col_date', 'value'=> 'alias', 'width'=>200, 'header'=> 'Псевдоним'),
										array('cellClass'=>'col_date', 'value'=> 'aliasfull', 'width'=>200, 'header'=> 'Ссылка на страницу')
									)
		);
		$this->attachBehavior(new Pages_Model_Behavior($this));
	}
	
	public function getLayouts() {
		$path = ROOT_PATH . "/site/themes/default/scripts/";
		$layouts = scandir ( $path );
		$res = array ();
		foreach ( $layouts as $layout ) {
			if ((! preg_match ( '/^\./', $layout )) && (! preg_match ( '/^index\./', $layout ))) {
				$name = preg_replace ( '/\.\S+$/', '', $layout );
				$res [$name] = $layout;
			}
		}
		return $res;
	}
	/*
	public function copy() {
		$model = new Zen_List('pages');
		$pages = $model->select()->getData("parent_id=0");
		$new_model = new Zen_List('pages_item');
		foreach ($pages as $page) {
			if ($new_model->select()->getOne("alias='". $page['alias'] ."'")) 
				throw new Exception('', 404);
			$page['type'] = 'page';
			$this->create($page);
		}
	}
	*/
}